home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / miscellaneous.lzh / Miscellaneous / Example4.c < prev    next >
C/C++ Source or Header  |  1990-02-06  |  5KB  |  170 lines

  1. /* Example4                                                     */
  2. /* This example shows how to handle double mouse button events. */
  3.  
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7.  
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13.  
  14. /* Declare a pointer to a Window structure: */ 
  15. struct Window *my_window;
  16.  
  17. /* Declare and initialize your NewWindow structure: */
  18. struct NewWindow my_new_window=
  19. {
  20.   50,            /* LeftEdge    x position of the window. */
  21.   25,            /* TopEdge     y positio of the window. */
  22.   400,           /* Width       400 pixels wide. */
  23.   100,           /* Height      100 lines high. */
  24.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  25.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  26.   CLOSEWINDOW|   /* IDCMPFlags  We will recieve a message when the user:  */
  27.                  /*             selects the Close window gad, or when the */
  28.   MOUSEBUTTONS,  /*             user presses/releases the mouse buttons.  */
  29.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  30.   WINDOWCLOSE|   /*             Close Gadget. */
  31.   WINDOWDRAG|    /*             Drag gadget. */
  32.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  33.   WINDOWSIZING|  /*             Sizing Gadget. */
  34.   ACTIVATE,      /*             The window should be Active when opened. */
  35.   NULL,          /* FirstGadget No gadgets connected to this window. */
  36.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  37.   "DOUBLE CLICK ON THE LEFT MOUSE BUTTON", /* Title Title of the window. */
  38.   NULL,          /* Screen      Connected to the Workbench Screen. */
  39.   NULL,          /* BitMap      No Custom BitMap. */
  40.   100,           /* MinWidth    We will not allow the window to become */
  41.   50,            /* MinHeight   smaller than 100 x 50, and not bigger */
  42.   400,           /* MaxWidth    than 400 x 200. */
  43.   200,           /* MaxHeight */
  44.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  45. };
  46.  
  47.  
  48.  
  49. main()
  50. {
  51.   /* Boolean variable used for the while loop: */
  52.   BOOL close_me;
  53.  
  54.   /* Store some data copied from the IntuitionMessage in these variables: */ 
  55.   ULONG class;           /* IDCMP flag. */
  56.   USHORT code;           /* Code. */
  57.   ULONG seconds, micros; /* Time. */
  58.   
  59.   /* Pointer to an IntuiMessage structure: */
  60.   struct IntuiMessage *my_message;
  61.  
  62.   /* Declare and initialize the time stamps: */
  63.   ULONG sec1 = 0;
  64.   ULONG mic1 = 0;
  65.   ULONG sec2 = 0;
  66.   ULONG mic2 = 0;
  67.  
  68.  
  69.  
  70.   /* Before we can use Intuition we need to open the Intuition Library: */
  71.   IntuitionBase = (struct IntuitionBase *)
  72.     OpenLibrary( "intuition.library", 0 );
  73.   
  74.   if( IntuitionBase == NULL )
  75.     exit(); /* Could NOT open the Intuition Library! */
  76.  
  77.  
  78.  
  79.   /* We will now try to open the window: */
  80.   my_window = (struct Window *) OpenWindow( &my_new_window );
  81.   
  82.   /* Have we opened the window succesfully? */
  83.   if(my_window == NULL)
  84.   {
  85.     /* Could NOT open the Window! */
  86.     
  87.     /* Close the Intuition Library since we have opened it: */
  88.     CloseLibrary( IntuitionBase );
  89.  
  90.     exit();  
  91.   }
  92.  
  93.  
  94.  
  95.   /* We have opened the window, and everything seems to be OK. */
  96.  
  97.  
  98.  
  99.   close_me = FALSE;
  100.  
  101.   /* Stay in the while loop until the user has selected the Close window */
  102.   /* gadget: */
  103.   while( close_me == FALSE )
  104.   {
  105.     /* Wait until we have recieved a message: */
  106.     Wait( 1 << my_window->UserPort->mp_SigBit );
  107.  
  108.     /* As long as we can collect messages successfully we stay in the */
  109.     /* while-loop: */
  110.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  111.     {
  112.       /* After we have successfully collected the message we can read */
  113.       /* it, and save any important values which we maybe want to check */
  114.       /* later: */
  115.       class   = my_message->Class;
  116.       code    = my_message->Code;
  117.       seconds = my_message->Seconds;
  118.       micros  = my_message->Micros;
  119.  
  120.  
  121.       /* After we have read it we reply as fast as possible: */
  122.       /* REMEMBER! Do never try to read a message after you have replied! */
  123.       /* (Some other process has maybe changed it.) */
  124.       ReplyMsg( my_message );
  125.  
  126.  
  127.       /* Check which IDCMP flag was sent: */
  128.       switch( class )
  129.       {
  130.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  131.                close_me=TRUE;
  132.                break;
  133.         
  134.         case MOUSEBUTTONS: /* The user pressed/released a mouse button. */
  135.                if( code == SELECTDOWN )
  136.                {
  137.                  /* Left button pressed. */
  138.                  
  139.                  /* Save the old time: */
  140.                  sec2 = sec1;
  141.                  mic2 = mic1;
  142.     
  143.                  /* Get the new time: */
  144.                  sec1 = seconds;
  145.                  mic1 = micros;
  146.     
  147.                  /* Check if it was a double-click or not: */
  148.                  if( DoubleClick( sec2, mic2, sec1, mic1 ) )
  149.                  {
  150.                    printf("Double-Click!\n");
  151.                    /* Reset the values: */
  152.                    sec1 = 0;
  153.                    mic1 = 0;
  154.                  }
  155.                }
  156.                break;
  157.       }
  158.     }
  159.   }
  160.  
  161.  
  162.  
  163.   /* Close the window: */
  164.   CloseWindow( my_window );
  165.  
  166.  
  167.  
  168.   /* Close the Intuition Library: */
  169.   CloseLibrary( IntuitionBase );
  170. }